package com.common.service;

import java.util.List;
import java.util.Map;

import com.common.dao.IBaseDao;
import com.common.entity.PageBean;
import com.luckmgr.entity.db.Company;

public class BaseService<E> implements IBaseService<E>{

	private IBaseDao<E> baseDao;

	public IBaseDao<E> getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(IBaseDao<E> baseDao) {
		this.baseDao = baseDao;
	}

	@Override
	public PageBean<E> selectListPage(Map<String,Object> map, Integer page) {
		Integer totalPages = baseDao.selectCount(map);
		PageBean<E> pageBean = new PageBean<E>();
		pageBean.setCurrentPage(page);
		pageBean.setTotalResults(totalPages);
		map.put("start", pageBean.getStart());
		map.put("pageSize", pageBean.getPageSize());
		List<E> list = baseDao.selectListPage(map);
		pageBean.setData(list);
		return pageBean;
	}

	@Override
	public void updateEntity(E e) {
		baseDao.updateByPrimaryKeySelective(e);
		
	}

	@Override
	public void addEntity(E e) {
		baseDao.insertSelective(e);
	}

	@Override
	public E selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return baseDao.selectByPrimaryKey(id);
	}

	@Override
	public void deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		baseDao.deleteByPrimaryKey(id);
	}

	@Override
	public List<E> selectList(Map<String,Object> map) {
		return baseDao.selectList(map);
	}
	
}
